<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function* gen() {
                yield 111;
                let two = yield 222;
                console.log(two);
                yield 333;
            }
            // 获取迭代器对象 
        let iterator = gen();
        console.log(iterator.next());
        console.log(iterator.next());
        console.log(iterator.next('ccc')); //第三次调用函数的参数将作为第二个yield语句整体
        //返回的结果 Object
        // done: false
        // value: 111
        // __proto__: Object
        // Object
        // done: false
        // value: 222
        // __proto__: Object
        // ccc
        // Object
        // done: false
        // value: 333
        // __proto__: Object
        //生成器函数实例
        //需求 1s后控制台输出11 2s后输出22 3s后输出33
        setTimeout(() => {
            console.log(11);
        })
    </script>
</body>

</html>